/**
 * @see https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii/
 * y移除重复字符
 * @param {string} s
 * @param {number} k
 * @return {string}
 */
var removeDuplicates = function (s, k) {
  let reg = new RegExp(`([a-z])\\1{${k-1}}`);
  while(true) {
    if(reg.test(s)) {
      s = s.replace(reg, '');
    } else {
      break;
    }
  }
  console.log(s)
  return s;
};

removeDuplicates('pbbcggttciiippooaais', 2);